package com.ysqcould.web.controller.mp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.mp.domain.MpInfo;
import com.ysqcould.mp.service.IMpInfoService;

/**
 * 公众号管理Controller
 * 
 * @author jcd
 * @date 2022-10-18
 */
@RestController
@RequestMapping("/mp/info")
public class MpInfoController extends BaseController
{
    @Autowired
    private IMpInfoService mpInfoService;

    /**
     * 查询公众号管理列表
     */
    @PreAuthorize("@ss.hasPermi('mp:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(MpInfo mpInfo)
    {
        startPage();
        List<MpInfo> list = mpInfoService.selectMpInfoList(mpInfo);
        return getDataTable(list);
    }

    /**
     * 导出公众号管理列表
     */
    @PreAuthorize("@ss.hasPermi('mp:info:export')")
    @Log(title = "公众号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MpInfo mpInfo)
    {
        List<MpInfo> list = mpInfoService.selectMpInfoList(mpInfo);
        ExcelUtil<MpInfo> util = new ExcelUtil<MpInfo>(MpInfo.class);
        util.exportExcel(response, list, "公众号管理数据");
    }

    /**
     * 获取公众号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mp:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mpInfoService.selectMpInfoById(id));
    }

    /**
     * 新增公众号管理
     */
    @PreAuthorize("@ss.hasPermi('mp:info:add')")
    @Log(title = "公众号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpInfo mpInfo)
    {
        final AjaxResult result = mpInfoService.insertMpInfo(mpInfo);
        return result;
    }

    /**
     * 修改公众号管理
     */
    @PreAuthorize("@ss.hasPermi('mp:info:edit')")
    @Log(title = "公众号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpInfo mpInfo)
    {
        return toAjax(mpInfoService.updateMpInfo(mpInfo));
    }

    /**
     * 删除公众号管理
     */
    @PreAuthorize("@ss.hasPermi('mp:info:remove')")
    @Log(title = "公众号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mpInfoService.deleteMpInfoByIds(ids));
    }
}
